package com.teapos.web;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.teapos.service.PrintService;
import com.teapos.util.Maps;
import com.teapos.util.Tool;

@SuppressWarnings({"rawtypes", "unchecked"})
@RequestMapping("/print")
@Controller
public class PrintController extends BaseController {
	
	@Autowired
	private PrintService printService;
	
	@RequestMapping("/setPrint")
	public String setPrint(String id,Model model) {
		model.addAttribute("id", id);
			return "print/install";
	}
	@RequestMapping("/index")
	public String index(HttpServletRequest req) {
		List stores = super.getUserStores(req);
		Map param = super.getParaMap(req);
		if(stores.size()==1) param.put("storeId", ((Map)stores.get(0)).get("store_id"));
		req.setAttribute("orders", printService.listOrders(param));
		req.setAttribute("page", Maps.newHashMap("pageNo", Tool.initPageNo(req.getParameter("pageNo")), 
				"total", printService.getCount(super.getParaMap(req)), "js", "turnpage"));
		return "print/index";
	}
	
	@RequestMapping("/detail")
	public String detail(HttpServletRequest req) {
		super.keepPara("url", req);
		return "print/detail";
	}

}
